/*
 * Copyright (C) 2014 Lucid Wolf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.lucidhex.hex;

import java.util.HashMap;

/**
 *
 * @author Wolf
 */
public class LucidBoardBounds {
    public static final LucidIndex ORIGIN = new LucidIndex(0,0,0);
    // 11 along the diagonal from center to center of super grids
    int aSum = 0;
    int bSum = 0;
    int cSum = 0;
    int num = 0;
    int maxRadius = 0;
    int erfRadius = 0;
    LucidIndex center = null;
    PlaneCoord centerStupid = null;
    public HashMap<LucidIndex, VisualSuperHex> superHexs = new HashMap<>();
    public void checkBounds(LucidIndex coord) {
        aSum = aSum + coord.A();
        bSum = bSum + coord.B();
        cSum = cSum + coord.C();
        num++;
        center = new LucidIndex(new LucidCoord(aSum/num, bSum/num, cSum/num));
        maxRadius = Math.max(erfRadius, radius(coord, ORIGIN));
        erfRadius = maxRadius - radius(center, ORIGIN);
        centerStupid = new PlaneCoord(center);
    }
    public static int radius(LucidIndex i, LucidIndex j){
        return 2*Math.max(Math.max(Math.abs(i.A()-j.A()), Math.abs(i.B()-j.B())),Math.abs(i.C()-j.C()));
    }
    public void buildSuperHex(){
        if(erfRadius/50 > 1){
            
        }
    }

    public PlaneCoord getCenter() {
        return centerStupid;
    }
    public double getStupidRadius() {
        return 1.0+erfRadius;
    }

    public void checkBoundsRemoval(LucidIndex coord) {
        aSum = aSum - coord.A();
        bSum = bSum - coord.B();
        cSum = cSum - coord.C();
        num--;
        center = new LucidIndex(new LucidCoord(aSum/num, bSum/num, cSum/num));
        maxRadius = Math.max(erfRadius, radius(coord, ORIGIN));
        erfRadius = maxRadius - radius(center, ORIGIN);
        centerStupid = new PlaneCoord(center);
    }
}
